module.exports = {
  up: async (queryInterface) => {
    // 删除用户表的 company_id 字段（用户只需要关联部门，通过部门获取公司）
    const tableInfo = await queryInterface.describeTable('users');
    
    if (tableInfo.company_id) {
      await queryInterface.removeColumn('users', 'company_id');
    }
  },

  down: async (queryInterface, Sequelize) => {
    // 如果需要回滚，重新添加 company_id
    await queryInterface.addColumn('users', 'company_id', {
      type: Sequelize.UUID,
      allowNull: true,
      references: {
        model: 'companies',
        key: 'id',
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL',
    });
    
    await queryInterface.addIndex('users', ['company_id']);
  },
};

